import router from '../router'
import store from '../store'
import {Message} from 'element-ui'
import{getToken} from '@/utils/auth'

const whiteList = ['/login'] // 不重定向白名单
router.beforeEach((to, from, next) => {

		console.log("路由跳转信息",to,from);
    let token=store.getters.loginToken
    if(to.meta.requireAuth){
      //需要登陆权限
      if(token){
        //有token,直接过
        next()
      }else{
        Message.error({message:'请先登陆!'})
        next({
          path:'/Login'
        })
      }
    }else{
      //不需要登陆权限
      //如果是登陆,先判断本地有没token,有的话直接跳过,实现免登陆
      if(getToken()){
        next({
          path:'/home'
        })
      }else{
        next()
      }
    }
   })

router.afterEach(() => {
  // NProgress.done() // 结束Progress
})
